#include "SampleImageWidget.h"

#include "qpainter.h"

SampleImageWidget::SampleImageWidget (QWidget * pParent) : QWidget(pParent)
{
    is_loaded = false;
}

SampleImageWidget::~SampleImageWidget()
{

}


void SampleImageWidget::setImage(const QImage & image)
{
    is_loaded = true;

    m_image = image;

    if ( m_image.width() > m_image.height())
        m_image = m_image.scaledToWidth(300);
    else
        m_image = m_image.scaledToHeight(300);

    update();
}

void SampleImageWidget::paintEvent(QPaintEvent * event)
{
    int gap;

    if ( is_loaded )
    {
        QPainter painter(this);

        painter.drawImage(0, 0, m_image);

        painter.end();
    }
}

